package com.zwkj.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zwkj.common.R;
import com.zwkj.design.FileSingleton;
import com.zwkj.domain.WFileT;
import com.zwkj.domain.WUserT;
import com.zwkj.pojo.vo.WFileTVo;
import com.zwkj.service.IWFileTService;
import com.zwkj.service.impl.PreviewWpsServiceImpl;
import com.zwkj.util.FileTemplateUtil;
import com.zwkj.util.FileUtils;
import com.zwkj.util.MinioFileUploadUtil;
import com.zwkj.util.RequestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.io.File;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Gap
 * @version 1.0
 * @createDate 时间:2023/12/12
 * @description 描述:
 */
@RestController
@RequestMapping("/console")
public class ConsoleController {
    @Autowired
    private PreviewWpsServiceImpl previewWpsService;
    @Autowired
    private IWFileTService iwFileTService;
    @Autowired
    private MinioFileUploadUtil minioFileUploadUtil;

    @Value("${wps.url}")
    private String wpsUrl;
    @Value("${wps.appid}")
    private String wpsAppId;

    @Value("${wps.host}")
    private String host;


    @GetMapping(value = "/download/{file_id}/{version}/{type}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    public @ResponseBody
    byte[] download(@PathVariable("file_id") String fileId, @PathVariable("version") int version, @PathVariable("type") String type) {
        System.out.println(host);
        String typeStr = type;
        byte[] bytes = null;
        //预览 模拟数据
        if (typeStr == null || typeStr.equals("") || typeStr.equals("1")) {
            WFileTVo file = FileSingleton.getFile(fileId);
            bytes = minioFileUploadUtil.minioUrlDownload(file.getDownloadUrl());
            //删除filesing
//            FileSingleton.delFileMap(fileId);
        }
        //数据编辑
        if (typeStr != null && !typeStr.equals("") && typeStr.equals("2")) {
            WFileT wFileT = iwFileTService.getById(fileId);
            bytes = minioFileUploadUtil.minioUrlDownload(wFileT.getDownloadUrl());
        }


        return bytes;
    }

}
